package tazadum.razzmatazz.scene;

import javax.media.opengl.GLAutoDrawable;

import tazadum.engine.Engine;
import tazadum.engine.event.SyncEventQueue;
import tazadum.engine.scene.Scene;

public class CurveTestScene implements Scene {
	// private static final float LENGTH = 2f;
	//
	// private static int MAX_SEGMENTS = 10;
	// private static int SEGMENT_SIZE = 50;
	//
	// private FloatBuffer vertices;
	// private int points;
	// private int visiblePoints;
	//
	// private final Vector position = new Vector();
	// private final List<Vector> segments = new LinkedList<Vector>();

	// private SyncEvent growAlpha;
	// private SyncEvent targetAlpha;

	// private BeizerCurve2d curve;

	// private int width;
	// private int height;

	public CurveTestScene() {
	}

	@Override
	public void loadResources(final Engine engine, final SyncEventQueue queue) {
		// final PeriodicSyncEventChannel eventChannel = new PeriodicSyncEventChannel(LENGTH, 0,
		// true);
		// growAlpha = new AfterSyncEvent(eventChannel, LENGTH);
		// targetAlpha = new PulseSyncEvent(eventChannel);

		// curve = new BeizerCurve2d();
		// curve.add(Vector.at(0, 0, 0), Vector.at(400, 50, 2), Vector.at(175, 100, 4),
		// Vector.at(100, 100, 6));
		//
		// vertices = BufferUtil.newFloatBuffer(3 * MAX_SEGMENTS * SEGMENT_SIZE);
		// vertices.position(0);
		//
		// for (int i = 0; i < MAX_SEGMENTS * SEGMENT_SIZE; i++) {
		// final float time = 6 * (i / ((float) MAX_SEGMENTS * SEGMENT_SIZE));
		// final Vector p = curve.calculate(time);
		// vertices.put(p.x);
		// vertices.put(p.y);
		// vertices.put(0);
		// }
		// vertices.position(0);
	}

	@Override
	public void init(final Engine engine, final GLAutoDrawable drawable, final SyncEventQueue queue) {
		// final GL gl = drawable.getGL();

		// width = drawable.getWidth();
		// height = drawable.getHeight();
		//
		// gl.glEnable(GL.GL_LINE_SMOOTH);
		// gl.glEnable(GL.GL_BLEND);
		// gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
		// gl.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_DONT_CARE);
		// gl.glLineWidth(4f);

		// vertices = BufferUtil.newFloatBuffer(3 * MAX_SEGMENTS * SEGMENT_SIZE);
		// vertices.position(0);

		// segments.add(new Vector());
		// addSegment();
		// renderPoints();
	}

	@Override
	public void display(final GLAutoDrawable drawable, final SyncEventQueue queue, final float time) {
		// final GL2 gl = drawable.getGL().getGL2();
		//
		// // update(time);
		//
		// visiblePoints = (int) (Math.min(time / 6, 1) * MAX_SEGMENTS * SEGMENT_SIZE);
		//
		// // render
		// gl.glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
		// gl.glColor3f(0.25f, 0.50f, 0.25f);
		//
		// gl.glMatrixMode(GL2.GL_MODELVIEW);
		// gl.glLoadIdentity();
		// gl.glTranslatef(position.x, position.y, 0);
		//
		// gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
		// gl.glVertexPointer(3, GL2.GL_FLOAT, 0, vertices);
		// gl.glDrawArrays(GL.GL_LINE_STRIP, 0, visiblePoints);
	}

	// private void update(final float time) {
	// if (targetAlpha.evaluate(time) > 0) {
	// addSegment();
	// renderPoints();
	// }
	//
	// final float alpha = growAlpha.evaluate(time);
	// visiblePoints = points - (int) ((1.0 - alpha) * SEGMENT_SIZE);
	//
	// final int size = segments.size();
	// if (size > 1) {
	// final Vector p0 = segments.get(size - 2);
	// final Vector p1 = segments.get(size - 1);
	//
	// position.x = -(alpha * (p1.x - p0.x) + p0.x) + width / 2;
	// position.y = -(alpha * (p1.y - p0.y) + p0.y) + height / 2;
	// }
	// }

	// private void renderPoints() {
	// vertices.rewind();
	// points = 0;
	//
	// final Iterator<Vector> segment = segments.iterator();
	// Vector last = segment.next();
	// while (segment.hasNext()) {
	// final Vector current = segment.next();
	//
	// for (int i = 0; i < SEGMENT_SIZE; i++) {
	// final float alpha = i / (float) SEGMENT_SIZE;
	// vertices.put(alpha * (current.x - last.x) + last.x);
	// vertices.put(alpha * (current.y - last.y) + last.y);
	// vertices.put(0);
	// points++;
	// }
	//
	// last = current;
	// }
	// vertices.rewind();
	// }
	//
	// private void addSegment() {
	// if (segments.size() >= MAX_SEGMENTS) {
	// segments.remove(0);
	// }
	//
	// final float angle = (float) (Math.random() * Math.PI * 2);
	// final float speed = 50;
	// final float dx = (float) (Math.cos(angle) * speed);
	// final float dy = (float) (Math.sin(angle) * speed);
	//
	// final Vector last = segments.get(segments.size() - 1);
	// final Vector node = new Vector(last.x + dx, last.y + dy, 0);
	// System.out.println("Adding segment: " + node);
	// segments.add(node);
	// }
}
